package org.codeart.singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 枚举方式实现单例
 */
public enum Singleton06 {

    INSTANCE;

    private Object data;

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static Singleton06 getInstance() {
        return INSTANCE;
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException,
            InstantiationException, IllegalAccessException {
        Class<Singleton06> clazz = Singleton06.class;
        Constructor<Singleton06> constructor = clazz.getDeclaredConstructor();
        constructor.setAccessible(true);
        Singleton06 instance1 = constructor.newInstance();
        Singleton06 instance2 = constructor.newInstance();
        System.out.println(instance1 == instance2);
    }
}
